﻿/// <reference path="../Plugins/jquery-1.10.2.min.js" />

//test
function DataService() {
    //Private fields
    
    //Public function
    this.Post = function (url, data, successCallback, errorCallback, completeCallback) {
        $.ajax({
            url: url,
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            data: JSON.stringify(data),
            success: function (data, textStatus, jqXHR) {
                if (!successCallback) {
                    return;
                }
                successCallback(data, textStatus, jqXHR);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                if (!errorCallback) {
                    return;
                }
                errorCallback(jqXHR, textStatus, errorThrown);
            },
            complete: function (jqXHR, textStatus) {
                if (!completeCallback) {
                    return;
                }
                completeCallback(jqXHR, textStatus);
            }
        });
    };

    this.Get = function (url, successCallback, errorCallback, completeCallback) {
        $.ajax({
            url: url,
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (data, textStatus, jqXHR) {
                if (!successCallback) {
                    return;
                }
                successCallback(data, textStatus, jqXHR);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                if (!errorCallback) {
                    return;
                }
                errorCallback(jqXHR, textStatus, errorThrown);
            },
            complete: function (jqXHR, textStatus) {
                if (!completeCallback) {
                    return;
                }
                completeCallback(jqXHR, textStatus);
            }
        });
    };
}